/*
 * $Id: StepTypeDAO.java,v 1.6 2010/06/21 16:04:49 navdeep_mahajan Exp $
 * 
 * Copyright (C) 2006 General Electric Company. All Rights Reserved.
 * 
 * This software is the confidential and proprietary information of the General
 * Electric Company (GE). You shall not disclose this software and shall use it
 * only in accordance with the terms of the license agreement you entered into
 * with GE.
 * 
 * GE MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
 * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
 * NON-INFRINGEMENT. GE SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
 * AS A RESULT OF USING, MODIFYING, OR DISTRIBUTING THIS SOFTWARE OR ITS
 * DERIVATIVES.
 */
package com.ge.healthcare.autosc.common.database.dao;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.ge.healthcare.autosc.common.ASCUtil;
import com.ge.healthcare.autosc.common.database.pojo.CfgStepType;

/**
 * @author 212042764
 * 
 */
public class StepTypeDAO extends BaseDAO implements IStepTypeDAO {
	/**
	 * Eclipse generated
	 */
	private static final long serialVersionUID = -4516421340848293512L;

	public StepTypeDAO() {
		super(CfgStepType.TABLE_NAME);
	}

	public CfgStepType getByID(Long id) {
		Object mappingDetails = findObjectByID(CfgStepType.COL_ID, id);
		if (!ASCUtil.isNullOrEmptyObject(mappingDetails)) {
			return (CfgStepType) mappingDetails;
		}
		return null;
	}

	public CfgStepType getStepType(String stepType, String serverName) {
		StringBuffer query = initQuery(CfgStepType.TABLE_NAME);
		query.append(" as model where model.");
		query.append(CfgStepType.COL_STEP_TYPE);
		query.append("= ? and model.");
		query.append(CfgStepType.COL_SERVER_NAME).append("= ?");
		
		logger.debug("query: " + query.toString() + " value: " + serverName);
		List<?> list = getHibernateTemplate().find(query.toString(),
				new Object[] { stepType, serverName });
		if (!ASCUtil.isNullOrEmptyList(list)) {
			return (CfgStepType) list.get(0);
		}
		return null;
	}
	
	public List<CfgStepType> getStepTypes(){
		StringBuffer query = initQuery(CfgStepType.TABLE_NAME);
		query.append(" order by stepType");
		List<?> list = getHibernateTemplate().find(query.toString());
		if (ASCUtil.isNullOrEmptyList(list)) {
			return null;
		}
		List<CfgStepType> stepTypes = new ArrayList<CfgStepType>();
		for (Object stepType : list){
			stepTypes.add((CfgStepType)stepType);
		}
		return stepTypes;
	}

	public Long getStepTypeID(String stepType, String hostName) {
		HashMap<String, Object> whereClause = new HashMap<String, Object>();
		whereClause.put(CfgStepType.COL_STEP_TYPE, stepType);
		whereClause.put(CfgStepType.COL_SERVER_NAME, hostName);
		List<?> stepTypes = findByProperties(whereClause);
		if (ASCUtil.isNullOrEmptyList(stepTypes)) {
			return null;
		}
		return ((CfgStepType) stepTypes.get(0)).getStepTypeId();
	}

	/**
	 * @see com.ge.healthcare.autosc.common.database.dao.BaseDAO#save(java.lang.Object)
	 */
	public void save(Object pojo) {
		super.save(pojo);
	}

	/**
	 * @see com.ge.healthcare.autosc.common.database.dao.IRequestTypeDAO#saveAlways(java.lang.Object)
	 */
	public void saveAlways(Object pojo) {
		super.save(pojo);
	}

	/**
	 * @see com.ge.healthcare.autosc.common.database.dao.BaseDAO#deleteByID(java.lang.Object)
	 */
	public void deleteByID(Object pojo) {
		super.deleteByID(pojo);
	}

	/**
	 * @see com.ge.healthcare.autosc.common.database.dao.BaseDAO#refresh(java.lang.Object)
	 */
	public void refresh(Object pojo) {
		super.refresh(pojo);
	}
}
